package com.hz.ruoyifarmbase.basedata.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hz.ruoyifarmbase.basedata.domain.AgrBaseWorker;
import com.hz.ruoyifarmbase.basedata.mapper.AgrBaseWorkerMapper;
import com.hz.ruoyifarmbase.basedata.service.AgrBaseWorkerService;
import com.ruoyi.common.core.web.domain.AjaxResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * @author 侯文波
 * @date 2025/3/5 11:23
 * @description:
 */
@Service
public class AgrBaseWorkerServiceImpl extends ServiceImpl<AgrBaseWorkerMapper, AgrBaseWorker> implements AgrBaseWorkerService {
    @Autowired
    private AgrBaseWorkerMapper agrBaseWorkerMapper;

    /**
     * @author 侯文波
     * 查询工人信息列表
     */
    @Override
    public List<AgrBaseWorker> selectAgrBaseWorkerList(AgrBaseWorker agrBaseWorker) {

        return agrBaseWorkerMapper.selectList(new QueryWrapper<AgrBaseWorker>().select(
                "worker_id",
                "worker_code",
                "worker_name",
                "worker_gender",
                "worker_card",
                "worker_age",
                "worker_phone",
                "worker_year",
                "worker_type",
                "create_by",
                "create_time",
                "update_by",
                "update_time").orderByDesc("create_time")
                // 模糊查询  编码 姓名  身份证号   手机号   工龄   工种
                .like(agrBaseWorker.getWorkerCode()!=null,"worker_code",agrBaseWorker.getWorkerCode())
                .like(agrBaseWorker.getWorkerName()!=null,"worker_name",agrBaseWorker.getWorkerName())
                .like(agrBaseWorker.getWorkerCard()!=null,"worker_card",agrBaseWorker.getWorkerCard())
                .like(agrBaseWorker.getWorkerPhone()!=null,"worker_phone",agrBaseWorker.getWorkerPhone())
                .eq(agrBaseWorker.getWorkerYear()!=null,"worker_year",agrBaseWorker.getWorkerYear())
                .like(agrBaseWorker.getWorkerType()!=null,"worker_type",agrBaseWorker.getWorkerType())

        );
    }


    /**
     *  新增工人信息
     * @param agrBaseWorker
     * @return
     */
    @Override
    public int insertAgrBaseWorker(AgrBaseWorker agrBaseWorker) {
        return agrBaseWorkerMapper.insert(agrBaseWorker);
    }

    /**
     * @author gmy
     * 获取质量检测员
     * @return
     */
    @Override
    public List<Map<String, Object>> getWorkerCheck() {
        return agrBaseWorkerMapper.selectByType("质量检测员");
    }

    @Override
    public Long countWorker() {
        return agrBaseWorkerMapper.selectCount(null);
    }


    /**
     *  修改工人信息
     * @param agrBaseWorker
     * @return
     */
    @Override
    public int updateAgrBaseWorker(AgrBaseWorker agrBaseWorker) {
        return agrBaseWorkerMapper.updateById(agrBaseWorker);
    }

    @Override
    public int deleteAgrBaseWorkerByWorkerId(Long workerId) {
        return agrBaseWorkerMapper.deleteById(workerId);
    }

    /**
     * @return:
     * @Author: xqd
     * @Date: 2025/3/17 16:42
     * @Description: app用户登录
     */
    @Override
    public AjaxResult login(AgrBaseWorker agrBaseWorker) {
        if (agrBaseWorkerMapper.login(agrBaseWorker) == null) {
            return AjaxResult.error("用户名或密码错误");
        }
        return AjaxResult.success("登录成功", agrBaseWorkerMapper.login(agrBaseWorker));
    }

    @Override
    public AjaxResult detail(Long workerId) {
        return AjaxResult.success(agrBaseWorkerMapper.detail(workerId));
    }
}
